#!/usr/bin/env bash
###################
path_to_x_cursors="../.images/cursors/x-cursors/"
path_to_links="./"
#
make_links() {
	function_name="make_links()"
	number_of_arguments=4
	if test ${#} -lt ${number_of_arguments} ; then
		echo "error: ${function_name}" 
		echo "       Function call with wrong number of arguments!"
		echo "       Function expects at least ${number_of_arguments} arguments!"
		echo "       Given arguments: ${@}"
		exit -1
	fi
	source_path=${1} ; shift
	destination_path=${1} ; shift
	source_filename=${1} ; shift
	destination_linkname_list=("$@")
	source_file=${source_path}${source_filename}
	if test ! -f "${source_file}" ; then
		echo "error: ${function_name}"
		echo "       Missing file: ${source_file}"
	else
		for i in ${destination_linkname_list[@]} ; do
			destination_link=${destination_path}${i}
			ln -svf "${source_file}" "${destination_link}"
		done
	fi
}
#
# process linkname list file
linkname_list_file='./linkname-list.txt'
# DO NOT SEPARATE grep AND white LINES!
grep -v '^#.*$\|^[[:space:]]*$' ${linkname_list_file} |\
while IFS='' read -r line || test -n "${line}" ; do
	make_links ${path_to_x_cursors} ${path_to_links} ${line}
done 
#
exit 0
